<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>智慧商贸 新建销售单 </title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="../../css/easyui.css"/>
    <style type="text/css">
        td{word-break: break-all; word-wrap:break-word;}
    </style>
</head>
<body>
<script src="../../js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="../../js/jquery.easyui.min.js" type="text/javascript"></script>
<script src="../../js/keys.js" type="text/javascript"></script>
<script src="../../js/ChinesePY.js" type="text/javascript"></script>
<script src="../../js/util.js" type="text/javascript"></script>
<script src="../../js/comm.js" type="text/javascript"></script>
<script src="../../js/JBusinessCom.js" type="text/javascript"></script>
<script src="../../js/JPageController.js" type="text/javascript"></script>
<script src="../../js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>

<div id="loading"></div>
<table style="min-width: 882px;" width="100%" border="0" height="100%" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" bgcolor="#e6e6e8" class="main">
<script src="../../js/jquery.autocomplete.min.js" type="text/javascript"></script>
<style type="text/css">
    .tipDiag {
        position: absolute;
        padding: 3px;
        font-size: 12px;
        border: 1px solid #F00;
        background: #FFF8CB url(../../images/warning.png) no-repeat 3px 3px;
        color: #000;
        display: none;
        padding-left: 16px;
    }

    .htd {
        background-color: #fdf7f7;
        text-align: center;
    }
</style>

<!--data-val:是否需要客户端验证-->
<!--data-val-required:验证类型和错误消息-->
<input data-val="true" data-val-required="SaleId 字段是必需的。" id="SaleId"  name="SaleId" type="hidden" value="00000000-0000-0000-0000-000000000000"/>
<input data-val="true" data-val-number="字段 IsToList 必须是一个数字。" data-val-required="IsToList 字段是必需的。" id="IsToList" name="IsToList" type="hidden" value="0"/>
<input data-val="true" data-val-number="字段 IsPrint 必须是一个数字。" data-val-required="IsPrint 字段是必需的。" id="IsPrint" name="IsPrint" type="hidden" value="0"/>
<input id="IsOpenProductSN" name="IsOpenProductSN" type="hidden" value="0"/>
<input type="hidden" name="hidProductsSn"/>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="500">
<tr>
<td valign="top">
<div class="buttonArea">
    <!-- left -->
     <div class="left">
                <a class="button PERM_PRINT"
                                   onclick="doPrint()">打印</a>
                            </div>
    <div class="right">
        <a class="button greenButton" onclick="parent.childAddTab('销售历史','Sale/List.html','慧管货')">历史单据</a>
    </div>
    <!-- right -->
</div>
<!-- buttonArea -->
<div class="clear height10"></div>
<div class="shadowBoxWhite receipts">
<table width="100%" border="0" cellspacing="0" cellpadding="5" class="title">
    <tr>
        <td width="30%" height="50">&nbsp;</td>
        <td width="40%" align="center" valign="top" class="text">商品销售单</td>
        <td width="30%" align="right" valign="bottom" class="font999" style="padding-bottom: 20px;">
            单据编号：<span id="SaleNo" name="SaleNo"></span></td>
    </tr>
</table>
  <div class="baseData">
            <div class="fl">
                <div class="fl">
                    客户&nbsp;:&nbsp;<span id="ClientId"></span>&nbsp;&nbsp;&nbsp;&nbsp;
                    出库仓库&nbsp;:&nbsp;<span id="WarehouseId"></span>
                </div>
            </div>
            <div class="fr">
                <div class="fl">
                    经手人&nbsp;:&nbsp;<span id="SaleUser"></span>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
                <div class="fl">
                    业务日期&nbsp;:&nbsp;<span id="SaleDate"></span>
                </div>
            </div>
</div>
<div class="baseData" style="display: none" id="receInfo">
    <div class="fl">
                <div class="fl">
                    &nbsp;&nbsp;&nbsp;&nbsp;送货日期&nbsp;:&nbsp;<span id="ReceDate"></span>&nbsp;&nbsp;&nbsp;&nbsp;
                    客户联系人&nbsp;:&nbsp;<span id="ClientLink"></span>&nbsp;&nbsp;&nbsp;&nbsp;
                    联系电话&nbsp;:&nbsp;<span id="ClientTel"></span>&nbsp;&nbsp;&nbsp;&nbsp;
                    送货地址&nbsp;:&nbsp;<span id="ReceAddress"></span>
                </div>
     </div>
</div>

<div class="clear height10"></div>
<div class="deliver" id="deliverGoods" style="display: none;">

</div>
<!-- deliver -->
<div class="clear height10"></div>
    <div id="cancelImg"></div>
<div class="tableDiv">
    <table width="100%" border="0" cellspacing="1" cellpadding="5" id="tabProducts">
        <tr>
            <th width="60" height="60" align="center" valign="middle">序号</th>
            <th align="left" valign="middle">商品名称/规格</th>
            <th width="150" align="center" valign="middle">商品编号</th>
            <th width="60" align="center" valign="middle">单价(元)</th>
            <th width="65" align="center" valign="middle">数量</th>
            <th width="50" align="center" valign="middle">单位</th>
            <th width="100" align="center" valign="middle">金额(元)</th>
            <!--<th width="60" align="center" valign="middle" id="IsOpenSaleTaxRate_2" style="display:none;">税率(%)</th>-->
            <!--<th width="100" align="center" valign="middle" id="IsOpenSaleTaxRate_3" style="display:none;">税后金额(元)</th>-->
            <th width="60" align="center" valign="middle" id="IsOpenSaleTaxRate_2" style="display:none;">税率(%)</th>
            <th width="100" align="center" valign="middle" id="IsOpenSaleTaxRate_3" style="display:none;">税后金额(元)</th>
            <th width="80" align="left" valign="middle">备注</th>
        </tr>
        <tr id="trTmp" style="display:none;">
            <td align="center" valign="middle" bgcolor="#FFFFFF">
                <span id="orderdiv"></span>
            </td>
            <td align="left" valign="middle" bgcolor="#FFFFFF">
                <span id="showProductName"></span>
            </td>
            <td align="left" valign="middle" bgcolor="#FFFFFF">
                <span id="showProductCode"></span>
            <td align="center" valign="middle" bgcolor="#FFFFFF">
                <span id="SalePrice"></span>
            </td>
            <td align="center" valign="middle" bgcolor="#FFFFFF">
                <span id="SaleCount"></span>
                <div class="sn" style="display: none" onmousemove=" $(this).children('div').show();" onmouseout="$(this).children('div').hide();">
                    <div class="snList" style="display: none;">
                    </div>
                </div>
            </td>
            <td align="center" valign="middle" bgcolor="#FFFFFF">
                <span id="UnitName"></span>
            <td align="center" valign="middle" bgcolor="#FFFFFF">
                <span id="EachSaleAmt"></span>
            </td>
            <td align="center" valign="middle" style="width: 60px;display:none;" bgcolor="#FFFFFF"
                name="IsOpenSaleTaxRate_4">
                <span id="EachTaxRate"></span>
            </td>
            <td align="center" valign="middle" style="width: 90px;display:none;" bgcolor="#FFFFFF"
                name="IsOpenSaleTaxRate_5">
                <span id="EachAfterTaxAmt"></span>
            </td>
            <td align="left" valign="middle" bgcolor="#FFFFFF">
                <span id="EachSaleRemark"></span>
            </td>
        </tr>
        <tr id="total">
            <td width="60" align="center" valign="middle" bgcolor="#FFFFFF" class="font14">合计</td>
            <td align="center" valign="middle" bgcolor="#FFFFFF"></td>
            <td width="150" align="left" valign="middle" bgcolor="#FFFFFF"></td>
            <td width="60" align="center" valign="middle" bgcolor="#FFFFFF"></td>
            <td width="50" align="center" valign="middle" bgcolor="#FFFFFF"><span id="spanTotalCount"></span></td>
            <td width="50" align="center" valign="middle" bgcolor="#FFFFFF"></td>
            <td width="100" align="center" valign="middle" bgcolor="#FFFFFF">
                <span class="fontRed">￥</span><span class=" font14 fontRed" id="spanTotalAmt"></span></td>
            <td align="center" valign="middle" style="display: none" bgcolor="#FFFFFF" id="IsOpenSaleTaxRate_7"></td>
            <td align="center" valign="middle" style="display: none" bgcolor="#FFFFFF" id="IsOpenSaleTaxRate_8"><span class="fontRed">￥</span>
                <span id="spanTaxAmt" class=" font14 fontRed">0.00</span></td>
            <td width="80" align="center" valign="middle" bgcolor="#FFFFFF"></td>
       </tr>
       <tr>
            <td valign="middle" align="center" bgcolor="#FFFFFF" >备注</td>
            <td  bgcolor="#FFFFFF"><span id="SaleRemark"></span></td>
            <!--<td colspan="4" bgcolor="#FFFFFF" style="display: none">-->
            <td colspan="4" bgcolor="#FFFFFF" id="IsOpenSaleTaxRate_9">
                    <table width="100%" border="0" cellspacing="0" cellpadding="3">
                        <tr>
                            <td>结算方式：</td>
                            <td><span id="AccountId">0.00</span></td>
                        </tr>
                        <tr>
                            <td width="60">折 扣 率：</td>
                            <td width="110"><span id="DiscountRate"></span>%</td>
                            <td width="60">折后应收：</td>
                            <td><span id="DisCountAmt"></span>元</td>
                            <!--<td width="60" align="right" style="display: none" id="IsOpenSaleTaxRate_1">税额：<span id="TaxAmt">0.00</span>元</td>-->
                            <td width="60" align="right" id="IsOpenSaleTaxRate_1" style="display: none">税额：</td>
                                <td id="IsOpenSaleTaxRate_6" style="display: none"><span id="TaxAmt">0.00</span>元</td>
                        </tr>
                        <tr>
                            <td>其他费用：</td>
                            <td><span id="OtherFee">0.00</span>元</td>
                            <td>应收金额：</td>
                            <td><span id="spanFAReceAmt">0.00</span>元</td>
                        </tr>
                    </table>
             </td>
            <td colspan="2" bgcolor="#FFFFFF">实收金额：
                <span class="font16 fontOrange" style="line-height: 25px;" id="ReceAmt"></span>元
            </td>
      </tr>

   </table>
</div>
<!-- tableDiv -->
<div class="bottomButtonArea">
    <div class="left font999">制单人：<span id="buildUser"></span>&nbsp;&nbsp;&nbsp;&nbsp;制单时间：<span id="buildTime"></span>
    </div>
</div>
<!-- buttonArea -->
</div>
<!-- receipts -->
    </td>
    </tr>
    </table>
</td>
</tr>
</table>

</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
    var IsOpenSaleTaxRate;
    var reqJson = {};
    var sysconf = getSysConfig();
    sysconf = eval("(" + sysconf + ")");
    IsOpenSaleTaxRate = sysconf['IsOpenSaleTaxRate'];
    var productSn = sysconf['IsOpenProductNum'];
    if(productSn == undefined){
        productSn = 0
    }
    if(IsOpenSaleTaxRate == undefined){
        IsOpenSaleTaxRate = 0
    }
    var saleId = requestUrlPara("SaleId");
    reqJson["SaleId"] = saleId;
    var result = parent.sale_bi.querySaleDetail(JSON.stringify(reqJson));
    var resultList = eval("(" + result + ")");
    var data = resultList["Data"];
    $("#SaleNo").text(data["SaleNo"]);
    $("#WarehouseId").text(data["WarehouseSimpleName"]);
    $("#SaleUser").text(data["SaleUser"]);
    $("#SaleDate").text(data["SaleDate"].substring(0,10));
    if(data["ReceDate"] != "" || data["ClientLink"] != "" || data["ReceAddress"] != ""){
        $("#receInfo").show();
        $("#ReceDate").text(data["ReceDate"].substring(0,10));
        $("#ClientLink").text(data["ClientLink"]);
        $("#ClientTel").text(data["ClientTel"]);
        $("#ReceAddress").text(data["ReceAddress"]);
    }
    $("#ClientId").text(data["ClientName"]);
    $("#buildUser").text(data["CreateUser"]);
    $("#buildTime").text(data["CreateDate"].replace("T"," "));
    $("#spanTotalAmt").text(getSystemDecimal(data["SaleAmt"]));
    $("#SaleRemark").text(data["SaleRemark"]);
    $("#DiscountRate").text(data["DiscountRate"]);
    $("#DisCountAmt").text(getSystemDecimal(data["DisCountAmt"]));
    $("#spanFAReceAmt").text(getSystemDecimal(data["FAReceAmt"]));
    $("#OtherFee").text(getSystemDecimal(data["OtherFee"]));
    $("#ReceAmt").text(getSystemDecimal(data["ReceAmt"]));
    $("#AccountId").text(data["AccountSimpleName"]);
    var spanTaxAmt = 0;
    var spanTotalCount = 0;
    var eachData = resultList["EachData"];
    var serialData = resultList["SerialData"];
    var obj = null;
    var judgeSaleIsOpenTax = false; //用于判断新增销售单时是否开启税率
    $(eachData).each(function(key,value){
       if(Number(value["TaxRate"]) > 0){
           judgeSaleIsOpenTax = true;
       }
    });
    for(var i = 0; i < eachData.length; i++){
        var trTmp = $("#trTmp").clone();
        trTmp.attr("id","");
        trTmp.show();
        trTmp.insertBefore($("#trTmp"));
        trTmp.children("td").eq(0).children("span").text(i+1);
        trTmp.children("td").eq(1).children("span").text(eachData[i]["ProductName"] + "/" + eachData[i]["ProductForm"]);
        trTmp.children("td").eq(2).children("span").text(eachData[i]["ProductCode"]);
        trTmp.children("td").eq(3).children("span").text(getSystemDecimal(eachData[i]["SalePrice"]));
        trTmp.children("td").eq(4).children("span").text(eachData[i]["SaleCount"]);
        trTmp.children("td").eq(5).children("span").text(eachData[i]["UnitName"]);
        trTmp.children("td").eq(6).children("span").text(getSystemDecimal(eachData[i]["SaleAmt"]));
        if(eachData[i]["SerialNo"] != "" && productSn == 1 && eachData[i]["SNManage"] != 0){
            trTmp.children("td").eq(4).children("div").show();
            var serialUl = [];
            serialUl[serialUl.length] = '<ul>';
            $(eachData[i]["SerialNo"]).each(function(key,value){
                serialUl[serialUl.length] = '<li><span class="snNum">'+ (key +1) + '</span><span class="snText">' + value["SerialNo"] + '</span></li>'
            });
            serialUl[serialUl.length] = '</ul>';
            serialUl = serialUl.join('')
            trTmp.children("td").eq(4).children("div").find(".snList").html(serialUl);
        }
        if('1' == IsOpenSaleTaxRate || judgeSaleIsOpenTax){
            trTmp.children("td").eq(7).children("span").text(eachData[i]["TaxRate"]);
            trTmp.children("td").eq(8).children("span").text(getSystemDecimal(eachData[i]["AfterTaxAmt"]));
        }
        trTmp.children("td").eq(9).children("span").text(eachData[i]["SaleRemark"]);
        spanTaxAmt += Number(eachData[i]["AfterTaxAmt"]);
        spanTotalCount += Number(eachData[i]["SaleCount"]);
    }
     $("#spanTotalCount").text(spanTotalCount);
     if('1' == IsOpenSaleTaxRate || judgeSaleIsOpenTax){
        $('#IsOpenSaleTaxRate_1').show()
        $('#IsOpenSaleTaxRate_2').show()
        $('#IsOpenSaleTaxRate_3').show()
        $('td[name="IsOpenSaleTaxRate_4"]').show()
        $('td[name="IsOpenSaleTaxRate_5"]').show()
        $('#IsOpenSaleTaxRate_6').show()
        $('#IsOpenSaleTaxRate_7').show()
        $('#IsOpenSaleTaxRate_8').show()
        $('#IsOpenSaleTaxRate_9').attr("colspan","6")
        $("#spanTaxAmt").text(getSystemDecimal(spanTaxAmt));
        $("#TaxAmt").text(getSystemDecimal((spanTaxAmt - data["SaleAmt"])*data["DiscountRate"]/100));

    }
         if(resultList["Data"]["WriteBack"] == 1){
            $("#cancelImg").addClass("cancelImg")
       }
})

    function doPrint(){
        var saleId=requestUrlPara("SaleId")
        OpenPrint('Sale/Print.html?SaleId='+saleId);
    }

</script>